package com.evaluation.kexingcp.psycho.evaluation.sys.utils

import cn.hutool.core.date.DatePattern
import cn.hutool.core.date.DateUtil
import com.evaluation.kexingcp.common.file.core.FileTemplate
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import java.io.File
import java.util.*

@Service
open class FileService(
    private val fileTemplate: FileTemplate,
) {
    @Value("\${file.bucketName:}")
    lateinit var bucketName: String


    @Value("\${file.oss.endpoint:}")
    lateinit var endpoint: String


    open fun uploadFile(file: File) : String {
        val fileName = "saas_evaluation" + "/" +
                DateUtil.format(Date(), DatePattern.NORM_DATE_PATTERN) + "/" + file.name
        fileTemplate.putObject(bucketName, fileName, file.inputStream())

        return "https://$bucketName.$endpoint/$fileName"
    }
}